package com.android.lovingpet.adopt.host.hostinfo.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.android.lovingpet.R;
import com.android.lovingpet.adopt.host.hostinfo.HostInfoPresenter;
import com.android.lovingpet.adopt.host.hostinfo.IHostInfoContract;
import com.android.lovingpet.base.TakePhotoFragment;
import com.android.lovingpet.bean.HostFoster;
import com.android.lovingpet.util.MyPhotoWindow;
import com.bumptech.glide.Glide;
import com.jph.takephoto.model.TResult;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by ikata on 2018/4/27.
 */

public class EvaluateFragment extends TakePhotoFragment<IHostInfoContract.View, HostInfoPresenter> implements IHostInfoContract.View ,View.OnClickListener{


    Unbinder unbinder;
    @BindView(R.id.tv_commit)
    TextView tvCommit;
    @BindView(R.id.et_content)
    EditText etContent;
    @BindView(R.id.iv_image)
    ImageView ivImage;
    @BindView(R.id.rb_anonymous)
    RadioButton rbAnonymous;
    private HostFoster hostFoster;

    @Override
    public void next(@Nullable Bundle bundle) {

    }

    @Override
    protected int setContentView() {
        return R.layout.fragment_evaluate;
    }

    @Override
    protected void onCreateView(View view) {
        unbinder = ButterKnife.bind(this, view);
        setTitle(view, "评价");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public HostInfoPresenter createPresenter() {
        return new HostInfoPresenter();
    }

    @Override
    public IHostInfoContract.View createView() {
        return this;
    }

    @Override
    public void takeSuccess(TResult result) {
        super.takeSuccess(result);
        Glide.with(getContext())
                .load(image)
                .into(ivImage);
    }

    @OnClick({R.id.tv_commit,R.id.iv_image})
    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.tv_commit:
                String content=etContent.getText().toString();
                int anonymous=0;
                if (rbAnonymous.isChecked()){
                    anonymous=1;
                }
                if (TextUtils.isEmpty(content.trim())){
                    Toast.makeText(getContext(),"请填写评价~",Toast.LENGTH_LONG).show();
                    return;
                }
                getPresenter().evaluate(hostFoster.getHostId(),content,1,anonymous);
                break;
            case R.id.iv_image:
                new MyPhotoWindow(takePhoto,getView()).create();
                break;
        }
    }


}
